home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / comm / mail / YamNet.lha / rexxtra12.lha / rexx / POP.rexx < prev    next >
OS/2 REXX Batch file  |  1990-03-18  |  2KB  |  96 lines

  1. /* POP.rexx */
  2.  
  3. /*
  4.      Format
  5.  
  6.        POP [TO <n>] [LIST] [CLEAR]
  7.  
  8.    List directories on stack, or "pop to" a given number on the stack.
  9.    Can clear stack as well
  10.  
  11.  */
  12.  
  13. signal off failure; signal off error; signal on syntax; signal on break_c
  14. call addlib 'rexxextra.library',-20,-30,0
  15.  
  16. facility = 'POP'
  17. retcode = 0
  18.  
  19. dtemplate = 'TO/K,CLEAR/S'
  20. template  = 'TO/K,CLEAR/S'
  21. args. = ''
  22.  
  23. parse arg g_c
  24. do while g_c='?'
  25.   options prompt dtemplate': '  /* this template is      */
  26.   parse pull g_c        /* displayed to the user */
  27.   if g_c='?' then do
  28.     g_s=sourceline(3)
  29.     if pos('/*',g_s)=0 then break; if pos('*/',g_s)>0 then break
  30.     say
  31.     g_s=sourceline(4)
  32.     do i=5 while pos('*/',g_s)=0; say g_s; g_s=sourceline(i); end
  33.     say
  34.     end
  35.   end
  36. interpret Cparse(g_c,template,'args')
  37. if args.ERRCODE > 1 then do; say facility'-E-BADARGS,' args.ERRTEXT; exit 5; end
  38.  
  39. 'cd | Execio var odir'
  40. cd. = odir
  41.  
  42. if args.CLEAR then do
  43.   do until rc > 0
  44.     'popcd >NIL:'
  45.     end
  46.   'cd' odir
  47.   signal GetOut
  48.   end
  49.  
  50. n = 0
  51. 'popcd >NIL:'
  52. if rc > 0 then do
  53.   say 'Nothing to "pop"'
  54.   exit 5
  55.   end
  56. do while rc = 0
  57.   'cd | Execio var x'
  58.   n = n + 1
  59.   cd.n = x
  60.   'popcd >NIL:'
  61.   end
  62.  
  63. if args.TO ~= '' then do
  64.   do i = n-1 to 1 by -1
  65.     'pushcd' cd.i
  66.     end
  67.   i = args.TO
  68.   'pushcd' odir
  69.   'pushcd' cd.i
  70.   end
  71. else do
  72.   say right(n,4)||'  '||cd.n
  73.   do i = n-1 to 1 by -1
  74.     say right(i,4)||'  '||cd.i
  75.     'pushcd' cd.i
  76.     end
  77.   'pushcd' odir
  78.   end
  79.  
  80. GetOut:
  81.   exit retcode
  82.  
  83. break_c:
  84. break_d:
  85. break_e:
  86. break_f:
  87.   say facility'-E-BREAK, Control-C interrupt'
  88.   exit 20
  89. failure:
  90.   say facility'-E-FAIL, Line:' sigl', Error:' rc; retcode = rc; signal GetOut
  91. syntax:
  92.   say facility'-E-SYNTAX, Line:' sigl', Error:' rc; retcode = rc; signal GetOut
  93. error:
  94.   say facility'-E-ERROR, Line:' sigl', Error:' rc; retcode = rc; signal GetOut
  95.  
  96.